/**
* Class to manage login function to be executed in the Servlet
* An example of call is:
* http://localhost:3141/idbcrownINServer/idbcrownINServer?action=IS_USER_OK&user=manzanot&pssw=m
*
* Project: idbCrownINServer
* Author:  TM
* Date:    05/05/2013
*
* History
* ------------------
* 05/05/2013 - TM - Initial version.
*/
 
 
package Functions;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import Application.*;
import DataModel.*;

public class login extends genericFunction
{
    /** data to fullfill header content */
    protected Object[][] readData;
    protected String     query;
    /** Class attributes */
    protected libSQLUtil sqlUtil;
    /** Application support */
    protected static libApplication appSupport;


     /** Constructor  */
    public login(HttpServletRequest _request, HttpServletResponse _response) throws IOException, ServletException
    {
       super(_request, _response);
       appSupport = libApplication.getInstance();
    }
    
    /** Execute function */
    public String execute()
    {
      String result = "0";
      String user   = getRequest().getParameter("user");
      String pssw   = getRequest().getParameter("pssw");
      
      try
      {
        /**
        sqlUtil = libSQLUtil.getInstance();
        String query = "select NAME from USERS where CODE='"+user+"' and PASSWORD='"+pssw+"'";
        readData     = sqlUtil.select(query);
        result       = readData[0][0] != null ? readData[0][0].toString() : null;
        */
        
        result = "User "+user+" is accepted";
        
        if (result == null)
           sendError();
//        else  
//           sendResponse(result);
      }
      catch(Exception ex)
      {
        sendError(ex);
      }
      
      return result;
    }
}